package cn.lisens.jpa.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.lisens.jpa.domain.PersonBase;
import cn.lisens.jpa.repository.PersonBaseRepository;

@Service
public class PersonBaseService {

	@Autowired
	private PersonBaseRepository personBaseRepository;
	
	public PersonBase save(PersonBase personBase) {
		PersonBase person = personBaseRepository.save(personBase);
		return person;
	}
	
	public List<PersonBase> findList(String idcard) {
		return personBaseRepository.findByIdcard(idcard);
	}

	public PersonBase update(PersonBase personBase) {
		personBaseRepository.findById(personBase.getId())
                .orElseThrow(() -> new RuntimeException("用户不存在"));
        
		return personBaseRepository.save(personBase);
	}
}
